package exttable.testversioning.tablemodel;

import exttable.view.ViewAnalysisVersionPhase;
import utils.Localisation;

import javax.swing.table.AbstractTableModel;
import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: Jun 18, 2010
 * Time: 5:16:08 PM
 * To change this template use File | Settings | File Templates.
 */
public class AnalysisPhaseModel extends AbstractTableModel {

    private Vector<ViewAnalysisVersionPhase> data;
    public static final int COLUMN_COUNT = 3;
    public static final int ANALYSIS = 0;
    public static final int PHASE = 1;
    public static final int VERSION = 2;


//    public AnalysisPhaseModel() throws Exception {
//        data = getData();
//    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public int getColumnCount() {
        return COLUMN_COUNT;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case ANALYSIS:
                return data.get(rowIndex).getAnalysis();
            case PHASE:
                return data.get(rowIndex).getPhase().getPhaseId();
            case VERSION:
                return data.get(rowIndex).getVersion().getVersionId();
            default:
                throw new IllegalArgumentException("no such value");
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case ANALYSIS:
                return Localisation.getMessage("table.column.analys");
            case PHASE:
                return Localisation.getMessage("table.column.phase");
            case VERSION:
                return Localisation.getMessage("table.column.version");
            default:
                throw new IllegalArgumentException("no such value");
        }
    }

//    private Vector<ViewAnalysisVersionPhase> getData() throws Exception {
//        Vector<ViewAnalysisVersionPhase> toReturn = new Vector<ViewAnalysisVersionPhase>();
//        Connection con = DbUtils.getDBConnectionGeneral();
//        PreparedStatement ps = con.prepareStatement(StoredQueries.getQuery(StoredQueries.ANALYSIS_PHASE));
//        try {
//            ResultSet rs = ps.executeQuery();
//            while (rs.next()) {
//                ViewAnalysisVersionPhase vavp = new ViewAnalysisVersionPhase();
//                ViewAnalysis va = new ViewAnalysis.Build()
//                        .nameEn(rs.getString("name_en"))
//                        .nameKz(rs.getString("name_kk"))
//                        .nameRu(rs.getString("name_ru"))
//                        .analysisVersionKey(rs.getString("analysisVersionKey"))
//                        .build();
//                vavp.setAnalysis(va);
//                ViewPhases vp = new ViewPhases();
//                vp.setPhaseId(rs.getString("phase"));
//                vavp.setPhase(vp);
//                ViewVersion vv = new ViewVersion();
//                vv.setVersionId(rs.getString("version"));
//                vavp.setVersion(vv);
//                toReturn.add(vavp);
//            }
//            con.close();
//            return toReturn;
//        }
//        catch (Exception e) {
//            e.printStackTrace();
//            throw e;
//        }
//        finally {
//            ps.close();
//            con.close();
//        }
//    }
}
